﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class cms_ChangeUserInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Response.Redirect("Default.aspx");
        }
        if (!IsPostBack)
        {
            DataRow dr = (DataRow)Session["user"];
            txtUsername.Enabled = false;
            txtUsername.Text = Convert.ToString(dr["Username"]);
            txtFirstName.Text = Convert.ToString(dr["FirstName"]);
            txtLastName.Text = Convert.ToString(dr["LastName"]);
            txtEmail.Text = Convert.ToString(dr["Email"]);
            txtPhone.Text = Convert.ToString(dr["Phone"]);
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        DataRow dr = (DataRow)Session["user"];
        DBClass db = new DBClass();
        int i = db.ChangeUserInfo(Convert.ToInt32(dr["ID"]), txtFirstName.Text.Trim(), txtLastName.Text.Trim(), txtEmail.Text.Trim(), txtPhone.Text.Trim());
        if (i > 0)
        {
            DataSet ds = db.GetAllUserInfo(i);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                Session["user"] = ds.Tables[0].Rows[0];
            }
            lbError.Text = "Update user info success !";
        }
    }
}